import request from '@/utils/request';
import type { PermissionData, MenuParams } from './type';

enum API {
  //获取全部菜单与按钮的标识数据
  ALLPERMISSION_URL = '/admin/acl/permission',
  //新增子菜单
  ADDMENU_URL = '/admin/acl/permission/save',
  //更新某一个已有菜单
  UPDATE_URL = '/admin/acl/permission/update',
  //删除某一个已有菜单
  DELETEMENU_URL = '/admin/acl/permission/remove/',
}

/**
 *
 *  获取全部菜单与按钮的标识数据
 */
export const getAllPermission = () => {
  return request<any, PermissionData>({
    url: API.ALLPERMISSION_URL,
    method: 'get',
  });
};

/**
 *
 *  添加或更新菜单
 * @param data MenuParams
 */
export const reqAddOrUpdateMenu = (data: MenuParams) => {
  if (data.id) {
    return request<any, any>({
      url: API.UPDATE_URL,
      method: 'put',
      data,
    });
  } else {
    return request<any, any>({
      url: API.ADDMENU_URL,
      method: 'post',
      data,
    });
  }
};

/**
 *
 *  删除菜单
 * @param id 菜单id
 */
export const reqDeleteMenu = (id: number) => {
  return request<any, any>({
    url: API.DELETEMENU_URL + id,
    method: 'delete',
  });
};
